package com.pay.sdk.service.pay;

import java.util.Map;

import com.pay.sdk.common.Configure;
import com.pay.sdk.service.IPostService;
import com.pay.sdk.util.MD5Utils;

public class ZsPrePayQuery extends IPostService {
	private static final String SERVICE_NAME = "api.zs.prePay.query";
	private static final String SERVICE_VERSION = "1.0";
	private static final String SERVICE_CHARSET = "UTF-8";
	private static final String SERVICE_SIGN_TYPE = "MD5";

	@Override
	public String exec(Map<String, String> params) {
		String result = "";
		try {
			// 通用参数
			params.put("version", SERVICE_VERSION);
			params.put("charset", SERVICE_CHARSET);
			params.put("sign_type", SERVICE_SIGN_TYPE);
			// 请求参数
			params.put("service", SERVICE_NAME);
			params.put("merchant_no", Configure.getMerchantNo());
			params.put("dateTime", params.get("dateTime"));
			params.put("type", params.get("type"));
			params.put("date", params.get("date"));
			if(params.get("type").equals("A")){
				params.put("bankSerialNo", params.get("bankSerialNo"));
			}else if(params.get("type").equals("B")){
				params.put("orderNo", params.get("orderNo"));
			}
			params.put("operatorNo", "9999");
			params = MD5Utils.signMap(params, SERVICE_SIGN_TYPE, Configure.getKey(), SERVICE_CHARSET);
			return txn(Configure.isDevEnv() ? Configure.PAY_GATEWAY_DEV_API : Configure.PAY_GATEWAY_API, params);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

}
